package com.wechat.dev.netty;

import org.springframework.stereotype.Component;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
@Component
public class FirstServer {
	
	private EventLoopGroup mainGroup;
	private EventLoopGroup chileGroup;
	private static ServerBootstrap serverBootstrap;
	private static ChannelFuture channelFuture;
	private static class SingletionFirstServer{
		static final FirstServer instance = new FirstServer();
	}
	
	public static FirstServer getInstance() {
		return SingletionFirstServer.instance;
	}
	
	public FirstServer(){
		mainGroup = new NioEventLoopGroup();
		chileGroup = new NioEventLoopGroup();
		serverBootstrap = new ServerBootstrap();
		serverBootstrap.group(mainGroup,chileGroup).channel(NioServerSocketChannel.class)
		   .childHandler(new PublicChildHandler());
	}
	public static void start() {
		channelFuture = serverBootstrap.bind(8088);
		System.err.println("netty 启动完毕");
	}
}
